package com.shenyi.common.service;


import com.shenyi.common.api.ISysMacroService;
import com.shenyi.common.dao.SysMacroMapper;
import com.shenyi.common.entity.SysMacroDO;
import com.shenyi.core.cache.J2CacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通用字典表Service实现类
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2017-08-22 11:48:16
 */
@Service("sysMacroService")
public class SysMacroServiceImpl implements ISysMacroService {

    @Autowired
    private SysMacroMapper sysMacroMapper;

    @Autowired
    private J2CacheUtils j2CacheUtils;

    @Override
    public SysMacroDO queryObject(Long macroId) {
        return sysMacroMapper.queryObject(macroId);
    }

    @Override
    public List<SysMacroDO> queryList(Map<String, Object> map) {
        return sysMacroMapper.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return sysMacroMapper.queryTotal(map);
    }

    @Override
    public int save(SysMacroDO sysMacro) {
        sysMacro.setGmtCreate(new Date());
        sysMacroMapper.save(sysMacro);
        j2CacheUtils.put("macroList", queryList(new HashMap<String,Object>()));
        return 1;
    }

    @Override
    public int update(SysMacroDO sysMacro) {
        sysMacro.setGmtModified(new Date());
        sysMacroMapper.update(sysMacro);
        j2CacheUtils.put("macroList", queryList(new HashMap<String,Object>()));
        return 1;
    }

    @Override
    public int delete(Long macroId) {
        sysMacroMapper.delete(macroId);
        j2CacheUtils.put("macroList", queryList(new HashMap<String,Object>()));
        return 1;
    }

    @Override
    public int deleteBatch(Long[] macroIds) {
        sysMacroMapper.deleteBatch(macroIds);
        j2CacheUtils.put("macroList", queryList(new HashMap<String,Object>()));
        return 1;
    }

    @Override
    public List<SysMacroDO> queryMacrosByValue(String value) {
        return sysMacroMapper.queryMacrosByValue(value);
    }
}
